//
// Created by wang on 2021/7/21.
//

#include "thr.h"
#include "cmn.h"
#include "enet.h"

ret_t e_sem_init(e_sem_t *sem, unsigned int value) {
    if (sem_init(sem, 0, value))
        return ERR_UTIL_CREATE_SEM_FAIL;
  return ENET_RET_SUCCESS;

}

void e_sem_destroy(e_sem_t *sem) {
  if (sem_destroy(sem))
    abort();
}

void e_sem_wait(e_sem_t *sem) {
  int r;

  do
    r = sem_wait(sem);
  while (r == -1 && errno == EINTR);

  if (r)
    abort();
}

void e_sem_post(e_sem_t *sem) {
  if (sem_post(sem))
    abort();
}
